/*global define console $win window Topbar:true*/
define(["jquery", "swiper-gallery"], function($) {
    function PageGallery(params) {
        this.params = params;
        this.myScroll = null;
        this.galleryData = null;
    }

    PageGallery.prototype.initDom = function() {
        $win.getTopbar().setTitle("gallery控件");
        $("#wrapper").height($(window).height() - 50);
    };

    PageGallery.prototype.initData = function() {
        var _this = this;
        var xhrArray = new Array();
        var jqXHR = $win.getData({
            "url": {
                "local": "/test/page_gallery",
                "remote": "/test/page_gallery"
            },
            "type": "pic"
        }, function(result) {
            if (result.success) {
                var html = "";
                var data = eval(result.value);
                _this.galleryData = data;
                for (var i = 0; i < data.length; i++) {
                    html += "<div class='swiper-slide'>";
                    html += "    <div style=\"width:100%;height:100%;\" file-loader='true' image-scale='false' image-type='fitCenter' file-type='pic' file-url='" + data[i].url + "'></div>";
                    html += "</div>";
                }
                console.log(html);
                $("#swiper-wrapper").html("").html(html);
            } else {
                $.MessageAlert({
                    "content": "请求数据失败"
                });
                _this.dataErrorArray.push(true);
            }
        });
        xhrArray.push(jqXHR);
        return xhrArray;
    };

    PageGallery.prototype.initEvent = function() {
        var _this = this;
        $win.initDownload($("[file-loader='true']"));
        _this.myGallery = $("#galleryWrapper").swiper({
            autoplay: 3000,
            pagination: ".swiper-pagination",
            onTap: function(swiper, event) {
                $win.log("111111");
                event.preventDefault();
                var showImages = {
                    images: _this.galleryData,
                    index: swiper.activeIndex
                };
                _this.createFunc(showImages);
            }
        });
    };

    //点击图片显示缩略图
    PageGallery.prototype.createFunc = function(params) {
        $win.showImages(params);
    };

    return PageGallery;
});
